package com.qiandw.mailSendService.controller;

import com.qiandw.mailSendService.service.MailSenderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class mailSenderController {

    private final MailSenderService mailSenderService;

    @Autowired
    public mailSenderController(MailSenderService mailSenderService) {
        this.mailSenderService = mailSenderService;
    }

    @RequestMapping("/simplemail")
    public Boolean mailSimpleSender(String receiver, String subject, String context){
        mailSenderService.setReceived(receiver);
        mailSenderService.sendSimpleMail(subject, context);
        return true;
    }

    @RequestMapping("/simplehtmlmail")
    public Boolean mailSimpleHtmlSender(String receiver, String subject, String context){
        mailSenderService.setReceived(receiver);
        mailSenderService.sendSimpleHtmlMail(subject, context);
        return true;
    }

    @RequestMapping("/mailTemplate")
    public Boolean mailTemplateHtmlSender(String receiver, String subject, String url, String context){
        mailSenderService.setReceived(receiver);
        Map<String, String> map = new HashMap<>();
        map.put("id", receiver);
        map.put("context", context);
        mailSenderService.sendTemplateMail(subject, map, url);
        return true;
    }
}
